from django.contrib import admin
from analysis.models import (
    KnowledgeMasteryProfile, KnowledgePracticeRecord,
    KnowledgeRelationship, StudyRecommendation
)


@admin.register(KnowledgeMasteryProfile)
class KnowledgeMasteryProfileAdmin(admin.ModelAdmin):
    list_display = [
        'student', 'knowledge_point', 'mastery_level',
        'learning_status', 'study_priority', 'needs_review'
    ]
    list_filter = ['learning_status', 'knowledge_point__subject', 'mastery_trend']
    search_fields = ['student__name', 'knowledge_point__name']
    readonly_fields = ['created_at', 'updated_at']
    list_editable = ['study_priority']

    def needs_review(self, obj):
        return obj.needs_review

    needs_review.boolean = True
    needs_review.short_description = '需复习'


@admin.register(KnowledgePracticeRecord)
class KnowledgePracticeRecordAdmin(admin.ModelAdmin):
    list_display = ['student', 'knowledge_point', 'result', 'score_impact', 'practiced_at']
    list_filter = ['result', 'knowledge_point__subject']
    search_fields = ['student__name', 'knowledge_point__name']
    readonly_fields = ['practiced_at', 'created_at']


@admin.register(StudyRecommendation)
class StudyRecommendationAdmin(admin.ModelAdmin):
    list_display = [
        'student', 'knowledge_point', 'recommendation_type',
        'priority_score', 'is_completed', 'is_active'
    ]
    list_filter = ['recommendation_type', 'is_completed']
    search_fields = ['student__name', 'knowledge_point__name']
    list_editable = ['is_completed']
    readonly_fields = ['created_at', 'updated_at']

    def is_active(self, obj):
        return obj.is_active

    is_active.boolean = True
    is_active.short_description = '活跃'


@admin.register(KnowledgeRelationship)
class KnowledgeRelationshipAdmin(admin.ModelAdmin):
    list_display = ['source_knowledge', 'relationship_type', 'target_knowledge', 'strength']
    list_filter = ['relationship_type']
    search_fields = ['source_knowledge__name', 'target_knowledge__name']